package org.cardoso.persistence.filter;

import java.util.ArrayList;
import java.util.List;


public class QueryFilter {
	
	public static final String SELECT_COUNT = " select count(entity) from class as entity ";
	public static final String SELECT = " from class as entity ";
	public static final String WHERE = " where ";
	public static final String ORDER_BY = " order by orderBy ";
    public static final Integer NO_PAGINATOR = -1;
    public static final String DIFFERENT = " <> ";
    public static final String LIKE = ") like ";
    public static final String OR = " or ";
    public static final String OPEN = "open";
    public static final String CLOSE = "close";
    public static final String MAIOR = " > ";
    public static final String MENOR = " < ";
    public static final String MAIOR_OU_IGUAL = " >= ";
    public static final String MENOR_OU_IGUAL = " <= "; 
    public static final String IS_NOT_NULL = " is not null ";
    public static final String IS_NULL = " is null ";
    public static final String VALUE_NULL = " valueNull ";
	
	private List<Filter> filters;
	private String orderBy;
	private Integer firstResult;
	private Integer maxResults;

	public QueryFilter() {
		super();
		this.filters = new ArrayList<Filter>();
	}
	
	public void add(Filter filter) {
		this.filters.add(filter);
	}
	
	public void add(String field, Object value) {
		this.filters.add(new Filter(field, value));
	}
	
	public void addArgument(String argument) {
		this.filters.add(new Filter(argument, VALUE_NULL));
	}
	
	public void removeFiltersNull() {
		// TODO ...		
	}

	public List<Filter> getFilters() {
		return filters;
	}

	public QueryFilter setFilters(List<Filter> filters) {
		this.filters = filters;
		return this;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public QueryFilter setOrderBy(String orderBy) {
		this.orderBy = orderBy;
		return this;
	}

	public Integer getFirstResult() {
		return firstResult;
	}

	public QueryFilter setFirstResult(Integer firstResult) {
		this.firstResult = firstResult;
		return this;
	}

	public Integer getMaxResults() {
		return maxResults;
	}

	public QueryFilter setMaxResults(Integer maxResults) {
		this.maxResults = maxResults;
		return this;
	}

	@Override
	public String toString() {
		return "QueryFilter [filters=" + filters.toString() + ", orderBy=" + orderBy
				+ ", firstResult=" + firstResult + ", maxResults=" + maxResults
				+ "]";
	}
	
}